define([],function(){

	var HttpPost = Java.type("org.apache.http.client.methods.HttpPost");
	var HttpClients = Java.type("org.apache.http.impl.client.HttpClients");
	var HttpEntity = Java.type("org.apache.http.HttpEntity");
	var RequestConfig = Java.type("org.apache.http.client.config.RequestConfig");
	var EntityUtils = Java.type("org.apache.http.util.EntityUtils");
	var NameValuePair = Java.type("org.apache.http.message.BasicNameValuePair");
	var UrlEncodedFormEntity = Java.type("org.apache.http.client.entity.UrlEncodedFormEntity");
	var INPUT_CHARSET_UTF8 = "utf-8";
	function post(url,list){

		var post = new HttpPost(url);
		var client = HttpClients.createDefault();
		var httpEntity = null;
		var returnValue = null;


		var requestConfig = RequestConfig.custom().setSocketTimeout(30000).setConnectTimeout(30000).build();
		post.setConfig(requestConfig);

		try {
			post.setEntity(new UrlEncodedFormEntity(list));
			var resp = client.execute(post);
			httpEntity = resp.getEntity();
			if(httpEntity!= null){
				returnValue = EntityUtils.toString(httpEntity, INPUT_CHARSET_UTF8);
			}
			// DEBUG("========= ajax result "+returnValue+" =========");
			EntityUtils.consume(httpEntity);
			resp.close();
		} catch (e) {
			e.printStackTrace();
			try {
				client.close();
			} catch (e1) {
				e1.printStackTrace();
			}
		}
		return returnValue;
	}
	function get(url){

	}
	return {
		post : function(url,data){
			var list = [];
			for(var name in data){
				list.push(new NameValuePair(name,data[name]));
			}
			return post(url,list);
		},
		get : function(url,data){
			return get(url,data);
		}
	}
});